//
//  LSWaitForExamineTableViewCell.m
//  LaSaCivilAffairsDepartment
//
//  Created by 聂志康 on 2018/12/25.
//  Copyright © 2018 wpkj. All rights reserved.
//

#import "LSWaitForExamineTableViewCell.h"
#import "LSWaitForExamineModel.h"
#import "LSInfoCollectDisplayListModel.h"

@interface LSWaitForExamineTableViewCell ()
@property (nonatomic, strong) UIView *customerContentView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *eventNumberLabel;
@property (nonatomic, strong) UILabel *addressLabel;
@property (nonatomic, strong) UIImageView *rightArrowImageView;

@property (nonatomic, strong) UILabel *isResultLabel;
@end

@implementation LSWaitForExamineTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = hexColor(FFFFFF);
//        UIView *customerContentView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, ScreenWidth, LSWaitForExamineTableViewCellHeight-10)];
//        self.customerContentView = customerContentView;
//        customerContentView.backgroundColor = UIColor.whiteColor;
//        self.selectionStyle = UITableViewCellSelectionStyleNone;
//        [self.contentView addSubview:customerContentView];
        [self.contentView addSubview:self.eventNumberLabel];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.addressLabel];
        [self.contentView addSubview:self.rightArrowImageView];
        [self.contentView addSubview:self.selectedButton];
        [self.contentView addSubview:self.isResultLabel];
        [self.contentView addSubview:self.lineView];
    }
    return self;
}

- (void)setModel:(LSWaitForExamineModel *)model {
    _model = model;
    self.nameLabelText = model.bpmBizTitle;
    self.eventNumberLabelText = model.taskName;
    self.addressLabelText = model.definitionName;
    self.selectedButton.selected = model.isSelected;
}

- (void)setDisplayListModel:(LSInfoCollectDisplayListModel *)displayListModel {
    _displayListModel = displayListModel;
    self.selectedButton.selected = displayListModel.isSelected;
}

//- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
//    [super setHighlighted:highlighted animated:animated];
//    WS
//    if (highlighted) {
//        if (animated) {
//            [UIView animateWithDuration:0.5 animations:^{
//                [weakSelf.customerContentView setBackgroundColor:hexColor(d9d9d9)];
//            }];
//        } else {
//            [weakSelf.customerContentView setBackgroundColor:hexColor(d9d9d9)];
//        }
//    } else {
//        if (animated) {
//            [UIView animateWithDuration:0.5 animations:^{
//                [weakSelf.customerContentView setBackgroundColor:UIColor.whiteColor];
//            }];
//        } else {
//            [weakSelf.customerContentView setBackgroundColor:UIColor.whiteColor];
//        }
//    }
//}
//
//- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
//    [super setSelected:selected animated:animated];
//    WS
//    if (selected) {
//        if (animated) {
//            [UIView animateWithDuration:0.5 animations:^{
//                [weakSelf.customerContentView setBackgroundColor:hexColor(d9d9d9)];
//            }];
//        } else {
//            [weakSelf.customerContentView setBackgroundColor:hexColor(d9d9d9)];
//        }
//    } else {
//        if (animated) {
//            [UIView animateWithDuration:0.5 animations:^{
//                [weakSelf.customerContentView setBackgroundColor:UIColor.whiteColor];
//            }];
//        } else {
//            [weakSelf.customerContentView setBackgroundColor:UIColor.whiteColor];
//        }
//    }
//}

- (void)layoutSubviews {
    [super layoutSubviews];
    WS
    [self.eventNumberLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.contentView.mas_top).with.offset(25);
        make.right.equalTo(weakSelf.contentView.mas_right).with.offset(-30);
    }];
    [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView.mas_left).with.offset(35);
        make.top.equalTo(weakSelf.contentView.mas_top).with.offset(10);
        make.right.equalTo(weakSelf.eventNumberLabel.mas_left).with.offset(-30);
    }];
    [self.addressLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.contentView.mas_left).with.offset(35);
        make.top.equalTo(weakSelf.contentView.mas_top).with.offset(40);
        make.right.equalTo(weakSelf.contentView.mas_right).with.offset(-30);
    }];
    [self.isResultLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.contentView.mas_right).with.offset(-50);
        make.centerY.equalTo(weakSelf.contentView.mas_centerY).with.offset(5);
    }];
}

- (void)setNameLabelText:(NSString *)nameLabelText {
    _nameLabelText = nameLabelText;
    self.nameLabel.text = nameLabelText;
}

- (void)setEventNumberLabelText:(NSString *)eventNumberLabelText {
    _eventNumberLabelText = eventNumberLabelText;
    self.eventNumberLabel.text = eventNumberLabelText;
}

- (void)setAddressLabelText:(NSString *)addressLabelText {
    _addressLabelText = addressLabelText;
    self.addressLabel.text = addressLabelText;
}

- (void)setIsResulted:(BOOL)isResulted {
    _isResulted = isResulted;
    self.isResultLabel.hidden = isResulted;
}
- (UIView *)lineView{
    if (!_lineView) {
        _lineView =[[UIView alloc]initWithFrame:CGRectMake(0, 65, ScreenWidth, 5)];
        _lineView.backgroundColor = hexColor(eeeeee);
    }
    return _lineView;
}
- (UIButton *)selectedButton {
    if (!_selectedButton) {
        _selectedButton = [[UIButton alloc] initWithFrame:CGRectMake(5, 9+10, 30, 30)];
        [_selectedButton setImage:[UIImage imageNamed:@"yuanquan"] forState:UIControlStateNormal];
        [_selectedButton setImage:[UIImage imageNamed:@"yuanquan_selected"] forState:UIControlStateSelected];
        [_selectedButton addTarget:self action:@selector(selectedButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _selectedButton;
}

- (void)selectedButtonClick:(UIButton *)button {
    button.selected = !button.isSelected;
    if (button.isSelected) {
        _model.isSelected = true;
        _displayListModel.isSelected = true;
    } else {
        _model.isSelected = false;
        _displayListModel.isSelected = false;
    }
    if ([self.delegate respondsToSelector:@selector(selectedButtonWithModel:)]) {
        [self.delegate selectedButtonWithModel:_model];
    }
}

- (UIImageView *)rightArrowImageView {
    if (!_rightArrowImageView) {
        _rightArrowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth-30+13/2, (LSWaitForExamineTableViewCellHeight-10-5)/2, 13/2, 22/2)];
        _rightArrowImageView.image = [UIImage imageNamed:@"jiantou"];
    }
    return _rightArrowImageView;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:15];
        _nameLabel.textColor = hexColor(333333);
    }
    return _nameLabel;
}

- (UILabel *)eventNumberLabel {
    if (!_eventNumberLabel) {
        _eventNumberLabel = [[UILabel alloc] init];
        _eventNumberLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:15];
        _eventNumberLabel.textColor = hexColor(666666);
        _eventNumberLabel.textAlignment = NSTextAlignmentRight;
    }
    return _eventNumberLabel;
}

- (UILabel *)addressLabel {
    if (!_addressLabel) {
        _addressLabel = [[UILabel alloc] init];
        _addressLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:15];
        _addressLabel.textColor = hexColor(666666);
    }
    return _addressLabel;
}

- (UILabel *)isResultLabel {
    if (!_isResultLabel) {
        _isResultLabel = [[UILabel alloc] init];
        _isResultLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Regular" size:13];
        _isResultLabel.textColor = NAV_COLOR;
        _isResultLabel.text = @"已审核";
        _isResultLabel.hidden = true;
    }
    return _isResultLabel;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

@end
